<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse;
use Hyperf\HttpServer\Router\Router;
use Hyperf\HttpServer\Contract\MiddlewareInterface;

Router::addRoute(['GET', 'POST', 'HEAD'], '/', 'App\Controller\IndexController@index');

Router::get('/favicon.ico', function () {
    return '';
});

// 显式添加点赞相关路由
Router::post('/api/v1/articles/{id}/like', 'App\Controller\v1\ArticlesController@like', ['middleware' => [\App\Middleware\TokenMiddleware::class]]);
Router::get('/api/v1/articles/{id}/likes', 'App\Controller\v1\ArticlesController@likeUsers', ['middleware' => [\App\Middleware\TokenMiddleware::class]]);

Router::post('/api/v1/articles/{id}/favorite', 'App\Controller\v1\ArticlesController@favorite', ['middleware' => [\App\Middleware\TokenMiddleware::class]]);

//文件下载接口
Router::addRoute(['GET', 'POST'],'/uploads/{ymd}/{filename}', function(HttpResponse $response, $ymd, $filename){
    $file_Name = BASE_PATH.'/uploads/'.$ymd.'/'.$filename;
    return $response->download($file_Name);
});
//websocket服务
Router::addServer('ws', function () {
    Router::get('/', 'App\Servers\Websocket');
});
